package resources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import daoImpl.DAOStation;
import daoInterface.IDAOStation;
import dto.DTOStation;

import model.Station;

public class StationInfoRessource 
{
	@Context
	UriInfo uriInfo;
	@Context
	Request request;
	String id = "1";
	/**
	 * Default constructor
	 */
	public StationInfoRessource(){}
	
	/**
	 * Constructor with 3 params
	 * @param uriInfo
	 * @param request
	 * @param id
	 */
	public StationInfoRessource(UriInfo uriInfo, Request request, String id)
	{
		this.uriInfo = uriInfo;
		this.request = request;
		this.id = id;
	}
	
	@GET
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	public Station getStation()
	{
		IDAOStation daoStation = new DAOStation();
		DTOStation dtoStation = daoStation.getStation(new Integer(id));
		Station station = null;
		
		if (dtoStation.getStationList() == null || dtoStation.getStationList().size() == 0)
		{
			// Dont have station with this specific id
			station = new Station();
			station.setId(new Integer(id));
		}	
		else
			// Found!
			station = dtoStation.getStationList().get(0);
		
		return station;
	}
	
	@GET
	@Produces(MediaType.TEXT_XML)
	public Station getStationHtml()
	{
		IDAOStation daoStation = new DAOStation();
		DTOStation dtoStation = daoStation.getStation(new Integer(id));
		Station station = null;
		
		if (dtoStation.getStationList() == null || dtoStation.getStationList().size() == 0)
		{
			// Dont have station with this specific id
			station = new Station();
			station.setId(new Integer(id));
		}	
		else
			// Found!
			station = dtoStation.getStationList().get(0);
		
		return station;
	}
	
	@Path("distance/{distance}")
	public String test(@PathParam("distance") String distance)
	{
		return "distance: " + distance;
	}
}
